package com.zhaowudi.wj.service;

import com.zhaowudi.wj.dao.BookDAO;
import com.zhaowudi.wj.pojo.Book;
import com.zhaowudi.wj.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class BookService {
    @Autowired
    BookDAO bookDAO;
    @Autowired
    CategoryService categoryService;
    @Transactional
    public List<Book> Alllist() {
        String sort = " order by id desc";
        System.out.println( bookDAO.findAll(sort));
        System.out.println( bookDAO.findAll(sort));
        System.out.println( bookDAO.findAll(sort));
        return bookDAO.findAll(sort);
    }

    public void add(Book book) {
        bookDAO.add(book);
    }

    public void addEX(List<Book> booklist) {
        bookDAO.addEX(booklist);
    }

    public void deleteById(int id) {
        bookDAO.deleteById(id);
    }

    public List<Book> listByCategory(int cid) {
        Category category = categoryService.get(cid);
        return bookDAO.findAllByCategory(category);
    }
}

